From 88400b1ef753aa691fcc9ce6fe7a774163f2e170 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 17 Feb 2025 11:49:35 +0100 Subject: [PATCH] add a wizard page to check terms of service should enable proper polling while the user check and signs the terms of service via teh web browser Signed-off-by: Matthieu Gallien Signed-off-by: Jyrki Gadinger --- src/gui/CMakeLists.txt | 2 + src/gui/wizard/flow2authcredspage.cpp | 2 +- src/gui/wizard/owncloudwizard.cpp | 18 +++++- src/gui/wizard/owncloudwizard.h | 14 ++-- src/gui/wizard/owncloudwizardcommon.h | 1 + src/gui/wizard/termsofservicewizardpage.cpp | 71 +++++++++++++++++++++ src/gui/wizard/termsofservicewizardpage.h | 54 ++++++++++++++++ src/gui/wizard/webviewpage.cpp | 2 +- 8 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 src/gui/wizard/termsofservicewizardpage.cpp create mode 100644 src/gui/wizard/termsofservicewizardpage.h diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 4bd77faba..5bb37c6ce 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -240,6 +240,8 @@ set(client_SRCS wizard/flow2authwidget.cpp wizard/owncloudsetuppage.h wizard/owncloudsetuppage.cpp + wizard/termsofservicewizardpage.h + wizard/termsofservicewizardpage.cpp wizard/owncloudwizardcommon.h wizard/owncloudwizardcommon.cpp wizard/owncloudwizard.h diff --git a/src/gui/wizard/flow2authcredspage.cpp b/src/gui/wizard/flow2authcredspage.cpp index e03b9a50f..a2f23f6ef 100644 --- a/src/gui/wizard/flow2authcredspage.cpp +++ b/src/gui/wizard/flow2authcredspage.cpp @@ -104,7 +104,7 @@ void Flow2AuthCredsPage::slotFlow2AuthResult(Flow2Auth::Result r, const QString int Flow2AuthCredsPage::nextId() const { - return WizardCommon::Page_AdvancedSetup; + return WizardCommon::Page_TermsOfService; } void Flow2AuthCredsPage::setConnected() diff --git a/src/gui/wizard/owncloudwizard.cpp b/src/gui/wizard/owncloudwizard.cpp index 9368b3d16..4fb364b8f 100644 --- a/src/gui/wizard/owncloudwizard.cpp +++ b/src/gui/wizard/owncloudwizard.cpp @@ -27,6 +27,7 @@ #include "wizard/welcomepage.h" #include "wizard/owncloudsetuppage.h" #include "wizard/owncloudhttpcredspage.h" +#include "wizard/termsofservicewizardpage.h" #include "wizard/owncloudadvancedsetuppage.h" #include "wizard/webviewpage.h" #include "wizard/flow2authcredspage.h" @@ -239,9 +240,12 @@ void OwncloudWizard::setRemoteFolder(const QString &remoteFolder) void OwncloudWizard::successfulStep() { - const int id(currentId()); + const WizardCommon::Pages id{static_cast(currentId())}; switch (id) { + case WizardCommon::Page_Welcome: + break; + case WizardCommon::Page_HttpCreds: _httpCredsPage->setConnected(); break; @@ -258,6 +262,10 @@ void OwncloudWizard::successfulStep() break; #endif // WITH_WEBENGINE + case WizardCommon::Page_TermsOfService: + _termsOfServicePage->initializePage(); + break; + case WizardCommon::Page_AdvancedSetup: _advancedSetupPage->directoriesCreated(); break; @@ -351,7 +359,13 @@ void OwncloudWizard::slotCurrentPageChanged(int id) void OwncloudWizard::displayError(const QString &msg, bool retryHTTPonly) { - switch (currentId()) { + switch (static_cast(currentId())) { + case WizardCommon::Page_Welcome: + case WizardCommon::Page_Flow2AuthCreds: + case WizardCommon::Page_WebView: + case WizardCommon::Page_TermsOfService: + break; + case WizardCommon::Page_ServerSetup: _setupPage->setErrorString(msg, retryHTTPonly); break; diff --git a/src/gui/wizard/owncloudwizard.h b/src/gui/wizard/owncloudwizard.h index da614b92d..7f950db06 100644 --- a/src/gui/wizard/owncloudwizard.h +++ b/src/gui/wizard/owncloudwizard.h @@ -33,6 +33,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcWizard) class WelcomePage; class OwncloudSetupPage; class OwncloudHttpCredsPage; +class TermsOfServiceWizardPage; class OwncloudAdvancedSetupPage; class OwncloudWizardResultPage; class AbstractCredentials; @@ -123,14 +124,15 @@ private: [[nodiscard]] QList calculateWizardPageSizes() const; AccountPtr _account; - WelcomePage *_welcomePage; - OwncloudSetupPage *_setupPage; - OwncloudHttpCredsPage *_httpCredsPage; - Flow2AuthCredsPage *_flow2CredsPage; - OwncloudAdvancedSetupPage *_advancedSetupPage; + WelcomePage *_welcomePage = nullptr; + OwncloudSetupPage *_setupPage = nullptr; + OwncloudHttpCredsPage *_httpCredsPage = nullptr; + Flow2AuthCredsPage *_flow2CredsPage = nullptr; + TermsOfServiceWizardPage *_termsOfServicePage = nullptr; + OwncloudAdvancedSetupPage *_advancedSetupPage = nullptr; OwncloudWizardResultPage *_resultPage = nullptr; AbstractCredentialsWizardPage *_credentialsPage = nullptr; - WebViewPage *_webViewPage = nullptr; + WebViewPage*_webViewPage = nullptr; QStringList _setupLog; diff --git a/src/gui/wizard/owncloudwizardcommon.h b/src/gui/wizard/owncloudwizardcommon.h index f5d7ba530..7c7714920 100644 --- a/src/gui/wizard/owncloudwizardcommon.h +++ b/src/gui/wizard/owncloudwizardcommon.h @@ -50,6 +50,7 @@ namespace WizardCommon { #ifdef WITH_WEBENGINE Page_WebView, #endif // WITH_WEBENGINE + Page_TermsOfService, Page_AdvancedSetup, }; diff --git a/src/gui/wizard/termsofservicewizardpage.cpp b/src/gui/wizard/termsofservicewizardpage.cpp new file mode 100644 index 000000000..5a7ec7a7a --- /dev/null +++ b/src/gui/wizard/termsofservicewizardpage.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) by Matthieu Gallien + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "termsofservicewizardpage.h" + +#include "account.h" +#include "owncloudsetupwizard.h" +#include "wizard/owncloudwizard.h" +#include "wizard/owncloudwizardcommon.h" +#include "connectionvalidator.h" + +#include +#include + +namespace OCC { + +OCC::TermsOfServiceWizardPage::TermsOfServiceWizardPage() + : QWizardPage() +{ + _layout = new QVBoxLayout(this); +} + +void OCC::TermsOfServiceWizardPage::initializePage() +{ +} + +void OCC::TermsOfServiceWizardPage::cleanupPage() +{ +} + +int OCC::TermsOfServiceWizardPage::nextId() const +{ + return WizardCommon::Page_AdvancedSetup; +} + +bool OCC::TermsOfServiceWizardPage::isComplete() const +{ + return false; +} + +void TermsOfServiceWizardPage::slotPollNow() +{ + _termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this}; + + connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &TermsOfServiceWizardPage::termsOfServiceChecked); + _termsOfServiceChecker->start(); +} + +void TermsOfServiceWizardPage::termsOfServiceChecked() +{ + if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) { + QDesktopServices::openUrl(_ocWizard->account()->url()); + } else { + _ocWizard->successfulStep(); + delete _termsOfServiceChecker; + _termsOfServiceChecker = nullptr; + } +} + +} diff --git a/src/gui/wizard/termsofservicewizardpage.h b/src/gui/wizard/termsofservicewizardpage.h new file mode 100644 index 000000000..86765e2fb --- /dev/null +++ b/src/gui/wizard/termsofservicewizardpage.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) by Matthieu Gallien + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#ifndef TERMSOFSERVICEWIZARDPAGE_H +#define TERMSOFSERVICEWIZARDPAGE_H + +#include + +class QVBoxLayout; + +namespace OCC { + +class OwncloudWizard; +class TermsOfServiceChecker; + +class TermsOfServiceWizardPage : public QWizardPage +{ + Q_OBJECT +public: + TermsOfServiceWizardPage(); + + void initializePage() override; + void cleanupPage() override; + [[nodiscard]] int nextId() const override; + [[nodiscard]] bool isComplete() const override; + +Q_SIGNALS: + void connectToOCUrl(const QString &); + void pollNow(); + +private Q_SLOTS: + void slotPollNow(); + void termsOfServiceChecked(); + +private: + QVBoxLayout *_layout = nullptr; + OwncloudWizard *_ocWizard = nullptr; + TermsOfServiceChecker *_termsOfServiceChecker = nullptr; +}; + +} // namespace OCC + +#endif // TERMSOFSERVICEWIZARDPAGE_H diff --git a/src/gui/wizard/webviewpage.cpp b/src/gui/wizard/webviewpage.cpp index 18acab0c4..a3587d1d8 100644 --- a/src/gui/wizard/webviewpage.cpp +++ b/src/gui/wizard/webviewpage.cpp @@ -92,7 +92,7 @@ void WebViewPage::cleanupPage() } int WebViewPage::nextId() const { - return WizardCommon::Page_AdvancedSetup; + return WizardCommon::Page_TermsOfService; } bool WebViewPage::isComplete() const { -- 2.30.2